package smartclass.slidingmenu.example;

import smartclass.data.FinalValues;
import smartclass.fragment.StudentFolderFragment;
import smartclass.fragment.TeacherFolderFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.jeremyfeinstein.slidingmenu.example.R;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public class BaseActivity extends SlidingFragmentActivity {

	private int mTitleRes;
	protected Fragment mFrag;
	boolean check_person = false;

	public BaseActivity(int titleRes) {
		mTitleRes = titleRes;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle(mTitleRes);
		Intent intent = getIntent();
		check_person = intent.getBooleanExtra("check_person", false);
		int id = intent.getIntExtra(FinalValues.ID, 1);
		FinalValues.displayNotification(getBaseContext(), check_person + ", "
				+ id);
		// set the Behind View
		setBehindContentView(R.layout.menu_frame);

		if (savedInstanceState == null) {
			FragmentTransaction t = this.getSupportFragmentManager()
					.beginTransaction();
			if (!check_person) {
				mFrag = new StudentFolderFragment(this, id);
			} else {
				mFrag = new TeacherFolderFragment(this, id);
			}

			t.replace(R.id.menu_frame, mFrag);
			t.commit();
		} else {
			mFrag = (Fragment) this.getSupportFragmentManager()
					.findFragmentById(R.id.menu_frame);
		}

		// customize the SlidingMenu
		SlidingMenu sm = getSlidingMenu();
		sm.setShadowWidthRes(R.dimen.shadow_width);
		sm.setShadowDrawable(R.drawable.shadow);
		sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		sm.setFadeDegree(0.35f);
		sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

		//getActionBar().setDisplayHomeAsUpEnabled(true);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	// @Override
	// public boolean onCreateOptionsMenu(android.view.Menu menu) {
	// if (check_person) {
	// FinalValues.displayNotification(getBaseContext(), "Teacher");
	// getMenuInflater().inflate(R.menu.main, menu);
	// } else {
	// FinalValues.displayNotification(getBaseContext(), "Student");
	// getMenuInflater().inflate(R.menu.main_student, menu);
	// }
	// // return super.onCreateOptionsMenu(menu);
	// return false;
	// }
	//
	// @Override
	// public boolean onOptionsItemSelected(android.view.MenuItem item) {
	//
	// switch (item.getItemId()) {
	// case android.R.id.home:
	// toggle();
	// return true;
	// case R.id.github:
	// showSecondaryMenu();
	// return true;
	// }
	// return super.onOptionsItemSelected(item);
	// }
}
